package com.jeff.utils.security;

import android.text.TextUtils;

/**
 * author：duff
 * version：1.0.0
 * date：2017/8/31
 * desc：
 */
public class SecurityUtil {

    public static final int ROUND_8BITS = 0x100;
    public static final int ROUND_4BITS = 0x10;
    public static final int RADIX_16 = 16;

    public static String toHexString(byte[] bytes) {
        if (bytes == null) {
            return "";
        }

        StringBuilder hexString = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            String hex = Integer.toHexString(0xff & bytes[i]);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }

        return hexString.toString();
    }

    public static String toHexString(String s) {
        if (TextUtils.isEmpty(s)) {
            return "";
        }

        return toHexString(s.getBytes());
    }

}
